package chixing.day16;


import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class ReaderDemo {
    public static void main(String[] args) {
        //1.创建字符读取流
        FileReader r = null;
        try {
            r = new FileReader("E:\\2025-cx\\project\\PJ\\J01\\Javase\\Temp\\char_hello.txt");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        //2.读取
        char[] charArr = new char[1024];
        int temp;
        int i = 0;
        try {
            while ((temp = r.read()) != -1 ){
                charArr[i++] =(char) temp;
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally { //3.关闭流
            if (r != null) {
                try {
                    r.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        String str = new String(charArr);
        String str1 = new String(charArr,0,i);//从第0个读取到第i个（i != -1）
        System.out.println(str1);
    }
}
